﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcDDshop2.Controllers
{
    public class SelectController : Controller
    {
        //
        // GET: /Select/

        //阅读页面
        public ActionResult Index(int id)
        {
            using (SqlConnection conn = new SqlConnection("Server=rm-bp13x228e5ip7ogsyzo.sqlserver.rds.aliyuncs.com,3433;uid=student;pwd=abc123!@#;database =Team4_DDBookDB"))
            {
                conn.Open();
                string sql = "select Book from BookInfo where ID=" + id;
                SqlCommand cmd = new SqlCommand(sql, conn);
                //设置执行时常
                cmd.CommandTimeout = 180;
                byte[] bytes = cmd.ExecuteScalar() as byte[];
                System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
                var pdf = bytes;
                HttpContext.Response.OutputStream.Write(bytes, 0, bytes.Length);
                HttpContext.Response.ContentType = "application/pdf";
                HttpContext.Response.End();
                //ViewBag.a = pdf;
                cmd.Dispose();
                conn.Close();
            }
            return View();
        }

    }
}
